package pers.qianyu.month_202012.date_20201226;

/**
 * 983. 最低票价
 * https://leetcode-cn.com/problems/minimum-cost-for-tickets/
 *
 * @author mizzle rain
 * @date 2020-12-26 21:26
 */
public class MincostTickets {
    public int mincostTickets(int[] days, int[] costs) {
        int len = days.length;
        int[] dp = new int[days[len - 1] + 1];
        int p = 0;
        for (int i = 1; i < dp.length; i++) {
            if (i != days[p]) {
                dp[i] = dp[i - 1];
            } else {
                dp[i] = Math.min(Math.min(
                        dp[Math.max(0, i - 1)] + costs[0],
                        dp[Math.max(0, i - 7)] + costs[1]),
                        dp[Math.max(0, i - 30)] + costs[2]);
                p++;
            }
        }
        return dp[dp.length - 1];
    }
}
